package org.linlinjava.litemall.admin.web2.order.resp;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.linlinjava.litemall.core.util.Util;
import org.linlinjava.litemall.db.domain.TOrder;
import org.linlinjava.litemall.db.domain.TOrderItem;
import org.linlinjava.litemall.db.domain.TUserInfo;
import org.linlinjava.litemall.db.enumeration.Const;

import java.util.List;

@ApiModel
public class OResp {
    @ApiModelProperty("id")
    private Integer id;
    @ApiModelProperty("订单类型")
    private String orderType;
    @ApiModelProperty("订单编号")
    private String transNo;
    @ApiModelProperty("销售价")
    private String saleAmount;
    @ApiModelProperty("购买数量")
    private String goodsNum;
    @ApiModelProperty("配送费")
    private String sendFree;
    @ApiModelProperty("实收款")
    private String payAmount;
    @ApiModelProperty("微信昵称")
    private String nickName;
    @ApiModelProperty("收货人姓名")
    private String name;
    @ApiModelProperty("联系电话")
    private String phone;
    @ApiModelProperty("送货地址")
    private String address;
    @ApiModelProperty("订单项")
    private List<Item> orderItems;

    public OResp() {
    }

    public void pushOrder(TOrder order) {
        if (order != null) {
            this.id = order.getId();
            this.orderType = Const.ORDER_TYPE.value(order.getOrderType());
            this.id = order.getId();
            this.transNo = order.getTransNo();
            if (order.getSaleAmount() != null)
                this.saleAmount = order.getSaleAmount().toString();

            this.sendFree = "0";
            if (order.getSendFree() != null)
                this.sendFree = order.getSendFree().toString();

            if (order.getPayAmount() != null)
                this.payAmount = order.getPayAmount().toString();
            this.name = order.getHarvesterName();
            this.phone = order.getHarvesterPhone();
            this.address = order.getTargetAddress();
            this.goodsNum = order.getGoodsNum().toString();
            push0(order);
        }
    }


    public String getGoodsNum() {
        return goodsNum;
    }

    public void setGoodsNum(String goodsNum) {
        this.goodsNum = goodsNum;
    }

    protected void push0(TOrder order) {
        //钩子
    }

    public void pushOrderItems(List<TOrderItem> items) {
        orderItems = Util.aList(items.size());
        if (items.size() > 0) {
            for (TOrderItem item : items) {
                orderItems.add(new Item(item));
            }
        }
    }

    public List<Item> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(List<Item> orderItems) {
        this.orderItems = orderItems;
    }

    public void pushUser(TUserInfo userInfo) {
        if (userInfo != null)
            this.nickName = userInfo.getNickname();
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTransNo() {
        return transNo;
    }

    public void setTransNo(String transNo) {
        this.transNo = transNo;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getSaleAmount() {
        return saleAmount;
    }

    public void setSaleAmount(String saleAmount) {
        this.saleAmount = saleAmount;
    }

    public String getSendFree() {
        return sendFree;
    }

    public void setSendFree(String sendFree) {
        this.sendFree = sendFree;
    }

    public String getPayAmount() {
        return payAmount;
    }

    public void setPayAmount(String payAmount) {
        this.payAmount = payAmount;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @ApiModel
    public static class Item {
        public Item() {
        }

        public Item(TOrderItem oItem) {
            this.mainTitle = oItem.getMainTitle();
            this.subTitle = oItem.getSubTitle();
            this.goodsNum = oItem.getGoodsNum();
            this.salePrice = oItem.getSalePrice().doubleValue();
            this.payPrice = oItem.getPayPrice().doubleValue();
        }

        @ApiModelProperty("主标题")
        private String mainTitle;
        @ApiModelProperty("子标题")
        private String subTitle;
        @ApiModelProperty("商品数量")
        private Integer goodsNum;
        @ApiModelProperty("销售价格")
        private Double salePrice;
        @ApiModelProperty("支付价格")
        private Double payPrice;

        public Double getPayPrice() {
            return payPrice;
        }

        public void setPayPrice(Double payPrice) {
            this.payPrice = payPrice;
        }

        public String getMainTitle() {
            return mainTitle;
        }

        public void setMainTitle(String mainTitle) {
            this.mainTitle = mainTitle;
        }

        public String getSubTitle() {
            return subTitle;
        }

        public void setSubTitle(String subTitle) {
            this.subTitle = subTitle;
        }

        public Integer getGoodsNum() {
            return goodsNum;
        }

        public void setGoodsNum(Integer goodsNum) {
            this.goodsNum = goodsNum;
        }

        public Double getSalePrice() {
            return salePrice;
        }

        public void setSalePrice(Double salePrice) {
            this.salePrice = salePrice;
        }
    }
}
